// component/top/top.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    multipleSlots: true
  },

  properties: {
    // 弹窗标题
    manName: {          // 属性名
      type: String,     // 类型（必填），目前接受的类型包括：String, Number, Boolean, Object, Array, null（表示任意类型）
      value: '李慧'     // 属性初始值（可选），如果未指定则会根据类型选择一个
    },
    avatarUrl: {
      type:String,
      value:"../../img/man.png"
    },
    attentionNum: {
      type:String,
      value:'0'
    },
    dynamicState: {
      type: String,
      value: '0'
    },
    toDoNum: {
      type: String,
      value: '0'
    },
    job:{
      type: String,
      value: '执行跟踪'
    },
    flagName:{
      type: String,
      value: 'enforce'
    },
    departmentList:{
      type: Array,
      value: new Array()
    },
    isHidden:{
      type: Boolean,
      value: false
    },//是否显示tab切换
    toDoNumSlt: {
      type: Boolean,
      value: true
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isSelected: false,
    showDepartment: false,
    job: '执行跟踪',
    flagName: "enforce",// 市场部("lawsuitInvest")
    menuTab: "list",//列表("list"),//关注("Attention"),//动态("Dynamic")
    toDoNumSlt: true,
    attentionNumSlt: false,
    dynamicStateSlt: false,
    ShareDocSlt: false,
    taskList: [
      {
        data: '0',
        name: '待办列表',
        style: '1px solid #ddd',
        slt: ''
      },
      {
        data: '0',
        name: '我的关注',
        style: '1px solid #ddd',
        slt: ''
      },
      {
        data: '0',
        name: '最新动态',
        style: '1px solid #ddd',
        slt: ''
      },
      {
        data: "0",
        name: '任务监控',
        style: '0',
        slt: ''
      }
    ],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    avatartap:function(){
      wx.showActionSheet({
        itemList: ['退出登录'],
        success: function (res) {
          console.log(res.tapIndex)
          if (res.tapIndex==0){
            wx.clearStorageSync();
            app.globalData.userInfo = null;
            app.globalData.loginUserInfo = '';
            wx.redirectTo({
              url: '../index/index'
            })
          }
        },
        fail: function (res) {
          console.log(res.errMsg)
        }
      })
    },
    // 去代办列表
    goIndex() {
      this.setData({
        toDoNumSlt: true,
        attentionNumSlt: false,
        dynamicStateSlt: false,
        ShareDocSlt: false,
      });
      //触发待办列表回调
      this.triggerEvent("goAgencyPage", this.data.flagName + "|" +"list")
      // console.log("flagName=", this.data.flagName)
    },

     //去我的关注
    goAttention:function(){
      this.setData({
        toDoNumSlt: false,
        attentionNumSlt: true,
        dynamicStateSlt: false,
        ShareDocSlt: false,
      });
      //触发我的关注
      this.triggerEvent("goMonitoring", this.data.flagName + "|" + "Attention");
    },

    //去文档库
    goShareDoc: function () {
      this.setData({
        toDoNumSlt: false,
        attentionNumSlt: false,
        dynamicStateSlt: false,
        ShareDocSlt: true,
      });
      //触发我的关注
      this.triggerEvent("goShareDoc", this.data.flagName + "|" + "ShareDoc");
    },
    //去最新动态
    goState() {
      this.setData({
        toDoNumSlt: false,
        attentionNumSlt: false,
        dynamicStateSlt: true,
        ShareDocSlt: false,
      });
      //触发我的关注
      this.triggerEvent("goState", this.data.flagName + "|" + "Dynamic");
      // wx.redirectTo({
      //   url: '../../pages/state/state',
      // })
    },

    //去任务监控
    goMonitoring() {
      // console.log("个人信息=", app.globalData.loginUserInfo)
      let jurisdiction = app.globalData.loginUserInfo.roles;
      if (this.data.flagName == 'enforce'){//执行
        if (jurisdiction.indexOf("ROLE_StepRecordMonitor") != -1) {
          wx.navigateTo({
            url: '../../pages/monitoring/monitoring?type=' + this.data.flagName,
          })
        }else{
          wx.showModal({
            title: '对不起',
            content: '您没有查看监控的权限',
            showCancel: false,
            cancelText: "知道了",
            success: function (res) {
              if (res.confirm) {
                // console.log('用户点击确定')
              } else if (res.cancel) {
                // console.log('用户点击取消')
              }
            }
          })
        }
      } else if (this.data.flagName == 'lawsuit'){//
        if (jurisdiction.indexOf("ROLE_LawsuitStepRecordMonitor") != -1) {
          wx.navigateTo({
            url: '../../pages/monitoring/monitoring?type=' + this.data.flagName,
          })
        }else{
          wx.showModal({
            title: '对不起',
            content: '您没有查看监控的权限',
            showCancel: false,
            cancelText: "知道了",
            success: function (res) {
              if (res.confirm) {
                // console.log('用户点击确定')
              } else if (res.cancel) {
                // console.log('用户点击取消')
              }
            }
          })
        }
      }
    },
    // 选择部门
    isShowDepartment() {
      let jobArray = this.data.departmentList;
      console.log("jobArray====", jobArray)
      let jobSlt = this.data.job;
      if (jobArray.length <= 1){
        return
      }

      if (!this.data.showDepartment) {
        for (let i = 0; i < jobArray.length; i++) {
          jobArray[i].selected = false;
          if (jobArray[i].name == jobSlt) {
            jobArray[i].selected = true;
          }
        }
        this.setData({
          showDepartment: true,
          departmentList: jobArray
        })
      } else {
        this.setData({
          showDepartment: false
        })
      }
    },
    departmentCon: function () {
      this.setData({
        showDepartment: false,
      })
    },
    //选中部门选择
    selectJob(e) {
      app.globalData.listRefresh = {};
      let jobArray = this.data.departmentList;
      let index = e.currentTarget.dataset.index;
      let flagName = jobArray[index].flagName;
      wx.setStorageSync("flagName", flagName);
      if (flagName == 'lawsuitInvest'){
        this.setData({
          showDepartment: false
        })
        wx.redirectTo({
          url: '../SuSong/ssIndex/ssIndex?flagName=' + flagName
        })
      } else if (flagName == 'nonLitigation') {
        this.setData({
          showDepartment: false
        })
        wx.redirectTo({
          url: '../FeiSu/fsIndex/fsIndex?flagName=' + flagName
        })
      } else if (flagName == "caseTrack") {
        this.setData({
          showDepartment: false
        })
        wx.redirectTo({
          url: '../Case/caseIndex/caseIndex?flagName=' + flagName
        })
      }else{
        this.setData({
          job: jobArray[index].name,
          flagName: flagName,
          showDepartment: false,
          toDoNumSlt: true,
          attentionNumSlt: false,
          dynamicStateSlt: false,
          ShareDocSlt:false
        })
        //触发取消回调
        this.triggerEvent("selectDepart", flagName)
      }
    }
  }
})
